package algorithm.sort;

/**
 * @Author liuhaoqi
 * @Date 2020/12/19 15:44
 * @Version 1.0
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {1, 2, 6, 7, 8, 9, 9, 1, 7};
        int[] arrs = bubbleSort(arr);
        for (int i : arrs) {
            System.out.println(i);
        }
    }

    public static int[] bubbleSort(int[] array) {
        int n = array.length;
        if (n == 0) {
            return array;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
        return array;
    }
}
